<template>
    <div>
        <h1>修改活动页面</h1>
        <table class="table">
            <tr>
                <td>上传活动图片</td>
                <td>
                    <input type="file" @change="Upload">
                    <img :src="axios.defaults.baseURL+dataa.img" style="width: 50px; height: 50px;">
                </td>
            </tr>
            <tr>
                <td>活动名称</td>
                <td><input type="text" v-model="dataa.hotelName"></td>
            </tr>

              <tr>
                <td>状态</td>
                <td>
                    <input type="radio" name="1" :value=true v-model="dataa.hotelStart">进行中
                    <input type="radio" name="1" :value=false v-model="dataa.hotelStart">已结束
                </td>
            </tr>
            <tr>
                <td>类型</td>
                <td>
                    <select v-model="dataa.hotelTypeId">
                        <option value="0">请选择</option>
                        <option v-for="a in can" :value="a.hotelTypeId">{{ a.hotelTypeName }}</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>创建时间</td>
                <td><input type="date" v-model="dataa.hotelTime"></td>
            </tr>
             <tr>
                <td>修改时间</td>
                <td><input type="date" v-model="dataa.createTime"></td>
            </tr>
 <tr>
                <td></td>
                <td><input type="button" value="活动修改" @click="Update"></td>
            </tr>

        </table>
    </div>
</template>
<script setup lang="ts">
import axios from 'axios';
import {ref,onMounted} from 'vue';
import {useRoute,useRouter} from 'vue-router';
const router = useRouter()
const route = useRoute()
onMounted(()=>{
    FT()
    Bang()
})

var can = ref({
    hotelTypeId: 0,
    hotelTypeName: ""
  })

  const Bang=()=>{
    axios.get("/api/HotelType/Show").then(res=>{
        can.value=res.data
    })
  }

const FT=()=>{
    let mid = route.query.id;
    axios.get("/api/Hotel/FT",{params:{id:mid}}).then(res=>{
        dataa.value= res.data
    })

}
var dataa  =ref({
  id: 0,
  img: "",
  hotelName: "",
  hotelStart: true,
  hotelTypeId: 0,
  hotelTime: "",
  createTime: ""
})
//文件上传方法
const Upload=(ev:any)=>{
    let f = ev.target.files[0]
    let fd = new FormData()
    fd.append("file",f)
    axios.post("/api/Upload/UpLoad",fd).then(res=>{
        dataa.value.img=res.data
    })
}

const Update=()=>{
    if(dataa.value.hotelName=="")
{
    alert("活动名称不能为空")
    return
}
    if(dataa.value.hotelTypeId==0)
{
    alert("类型不能为空")
    return
}
axios.post("/api/Hotel/Update",dataa.value).then(res=>{
        if(res.data>0)
    {
        alert("活动修改成功")
        router.push("/HotelShow");
    }
    else{
        alert("活动修改失败")
        
    }
    })
}

    


</script>
<style scoped>
</style>